package com.shashi.framework.base.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.util.CollectionUtils;

import com.shashi.framework.base.dao.BaseDao;
import com.shashi.framework.base.service.BaseService;

public class BaseServiceImpl<T> implements BaseService<T> {

	protected BaseDao<T> dao;

	public void add(T entity) {
		dao.add(entity);
	}

	public T findById(Serializable identifier) {
		List<T> entityList = dao.findByCriteria("id", identifier.toString());
		if ( !CollectionUtils.isEmpty(entityList) )	{
			return entityList.get(0);
		}
		return null;
	}

	/**
	 * @return the dao
	 */
	public BaseDao<T> getDao() {
		return dao;
	}

	/**
	 * @param dao
	 *            the dao to set
	 */
	public void setDao(BaseDao<T> dao) {
		this.dao = dao;
	}
}
